package com.qf.collection.list;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.UUID;

/**
 * 性能对比
 */
public class ArrayListVSLinkedList {

    public static void main(String[] args) {

        String[] arr = new String[100000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = UUID.randomUUID().toString();
        }

        ArrayList<String> list1 = new ArrayList<>();
        LinkedList<String> list2 = new LinkedList<>();
//        long start = System.currentTimeMillis();
//        for (int i = 0; i < arr.length; i++) {
//            list1.add(0,arr[i]);
//        }
//        long end = System.currentTimeMillis();
//        System.out.println(String.format("time used = %d", (end - start)));

//        long start1 = System.currentTimeMillis();
//        for (int i=0;i<10000;i++) {
//            list1.get(50000);
//        }
//        long end1 = System.currentTimeMillis();
//        System.out.println(String.format("time used = %d", (end1 - start1)));

        long start = System.currentTimeMillis();
        for (int i = 0; i < arr.length; i++) {
            list2.add(0,arr[i]);
        }
        long end = System.currentTimeMillis();
        System.out.println(String.format("time used = %d", (end - start)));

        long start1 = System.currentTimeMillis();
        for (int i=0;i<10000;i++) {
            list2.get(50000);
        }
        long end1 = System.currentTimeMillis();
        System.out.println(String.format("time used = %d", (end1 - start1)));

    }

}
